
#include "Task.h"
#include "../client-common/Device.h"

using namespace Client::Common;

map<string, CTaskCreator*> CTaskFactory::mCreators;

TaskRef CTaskFactory::Create(VersionTagRef vt) {
	map<string, CTaskCreator*>::iterator i = mCreators.find(vt->mTagName);
	if(i != mCreators.end()) {
		return i->second->Create(vt);
	}

	return TaskRef();
}

bool CTaskFactory::ExecAllFullyTask(string& dev, boost::shared_ptr<CConnection> conn)
{
	bool done = true;
	for(map<string, CTaskCreator*>::iterator i = mCreators.begin(); i != mCreators.end(); i++) {
		TaskRef t = i->second->CreateFullyTask(dev);
		if(t) {
			if(!t->Exec(conn)) done = false;
		}
	}

	return done;
}
